<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 1.随机10个0-100的数 放到数组中
    var arr = [];
    for (i = 1, b = 0; i <= 10; i++) {
        sum = c;
        var result = arr.push(sum);
        console.log(result);
        b += sum;

        console.log("累积和为" + b);
    }
    document.write(arr + "<br>");
    console.log(arr);

    //2.取10个数的的和 以及 平均值
    document.write("和等于" + b + "<br>");
    var ping = b / 10;
    console.log(ping);
    document.write("平均值等于" + ping + "<br>");

    //3.将大于平均值的数 放在新数组中
    console.log(arr[0]);
    var two = [];
    for (c = 0; c < 10; c++) {
        if (arr[c] > ping) {
            var conse = two.push(arr[c]);
            console.log(conse);
        }
    }
    document.write("大于平均数的数" + two + "<br>");
    console.log(two);

    //4.判断数组中(随机10个0-100的数)是否存在   60
    function pan() {
        var du = arr.includes(60);
        console.log(du);
        return du;
    }
    pan() == true ? document.write("数组中存在60" + "<br>") : document.write("数组中不存在60" + "<br>");

    //5.判断数组中(随机10个0-100的数)是否都大于 60
    function duan() {
        for (c = 0; c < 10; c++) {
            if (arr[c] <= 60) {
                return 1;
            }
        }
    }
    duan() == 1 ? document.write("数组中的数不是都大于60" + "<br>") : document.write("数组中的数都大于60" + "<br>");

    function duan2() {
        for (c = 0; c < 10; c++) {
            if (arr[c] <= 10) {
                return 1;
            }
        }
    }
    duan2() == 1 ? document.write("数组中的数不是都大于10" + "<br>") : document.write("数组中的数都大于10" + "<br>");


    //6.取十个数中最大值   => 打擂台
    function lei() {
        var max = arr[0];
        for (var i = 1; i < arr.length; i++) {

            /* if (x <= arr[i]) {
                var x = arr[i]
                var max = x;
            } else if (x > arr[i]) {
                var max = x;
            } */
            var y = arr[i];
            if(max < y){
                max = y;
            }
        }
        return max;
    }
    document.write("数组中最大的数为" + lei() + "<br>")

    //7.将10个数从小到大排   
    var min;
    for (var i = 0; i < arr.length; i++) {
        for (var j = i; j < arr.length; j++) {
            if (arr[i] > arr[j]) {
                min = arr[j];
                arr[j] = arr[i];
                arr[i] = min;
            }
        }
    }

    /* for (var i = 0; i < arr.length; i++) {
        if (arr[i] > arr[i + 1]) {
            max = arr[i];
            arr[i] = arr[i + 1];
            arr[i + 1] = max;
        }
    }
    console.log(arr); */
    document.write(arr.toString() + "<br />");
</script>

</html>